﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body>
    <div id="socket">
        <!--// swf dedicated div, doesn't modify layout //-->
    </div>
<div>Network status:<span id="aStatus" style="color:Blue;">Connecting...</span></div><br />
<div>Receiving Content:</div><br />
<div id="divRec" style="color:Blue;"></div>

    <script src="js/JQuery/jquery-1.3.2.min.js" type="text/javascript"></script>
    <script src="js/jsxmlsocket.js" type="text/javascript"></script>
<script type="text/javascript">
    var connected = false;//连接状态
    var element = document.getElementById("aStatus");//存储网络连接状态的元素
    var DataString="";//存储收到的字符串
    var xmls = new jsXMLSocket();
    var divRec=document.getElementById("divRec");
    // When the socket is added the to document
    xmls.onReady = function() 
    {
        xmls.connect("58.60.185.172", 9800);
        element.innerHTML='Connecting...';
    }

    // Connection attempt finished
    xmls.onConnect = function(success, error) 
    {
        if(success) 
        {
            xmls.send('init');
            connected = true;
            element.innerHTML = 'Connected';                                      
        } 
        else 
        {
			alert(error);
            element.innerHTML='Connecting...';
            connected = false;
            setTimeout(function(){xmls.onReady()},1000);
        }
    }

    // Server closed socket
    xmls.onClose = function() 
    {
        element.innerHTML='Connecting...';
        setTimeout(function(){xmls.onReady()},1000);
    }

    // Received data
    xmls.onData = function(data) 
    {
        if(data!="")
        {
            DataString+=data.toString();
            divRec.innerHTML=DataString;
        }
    }
    window.onload=function()
    {
        //try
        //{
            xmls.setup('#socket');
        //}
        //catch(e){}
    }
</script>
</body>
</html>
